package com.study.demo.aop.demo1_2.pointcut;

import com.study.demo.aop.demo1_2.operation.LogOperationSource;
import org.springframework.aop.support.StaticMethodMatcherPointcut;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import java.io.Serializable;
import java.lang.reflect.Method;

/**
 * @author: elvin
 * @time: 2019-10-16 14:30
 * @desc:
 **/
public abstract class LogOperationSourcePointcut extends StaticMethodMatcherPointcut implements Serializable {
    //根据当前被执行的方法和目标类, 判断是否满足切入条件
    @Override
    public boolean matches(Method method, Class<?> targetClass) {
        LogOperationSource los = getLogOperationSource();
        //los不等于空, 且 log操作类也不等于空
        return los != null && los.getLogOperations(method, targetClass) != null;
    }

    @Nullable
    protected abstract LogOperationSource getLogOperationSource();

    /*@Override
    public boolean equals(Object other) {
        if(this == other){
            return  true;
        }

        if(!(other instanceof  LogOperationSourcePointcut)){
            return false;
        }

        LogOperationSourcePointcut otherPc =  (LogOperationSourcePointcut) other;
        return ObjectUtils.nullSafeEquals(getLogOperationSource(), ((LogOperationSourcePointcut) other).getLogOperationSource());
    }*/
}
